// pages/my/gereninfo/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    formdata:{},
    uid:0,
    userinfo:{},
      isbianji:0
  },

  formSubmit:function(e){
    // console.log(this.data.formdata.sex != '男')
    if(this.data.formdata.contract.length != 11){
        wx.showToast({
            title: '请正确填写联系方式',
            icon:'none',
            duration: 2000
        })
        return ;
    }
    if(this.data.formdata.sex != '男' && this.data.formdata.sex != '女'){
        wx.showToast({
            title: '请正确填写性别，男或女',
            icon:'none',
            duration: 2000
        })
        return ;
    }
    if(this.data.formdata.old <0 || this.data.formdata.old >200){
          wx.showToast({
              title: '请正确填写年龄',
              icon:'none',
              duration: 2000
          })
          return ;
      }
    wx.request({
      url:getApp().data.server+'/index.php/Tongcheng/Book/updateUserInfo',
      data: {
         formData:JSON.stringify(this.data)
      },
      header: {'content-type': 'application/x-www-form-urlencoded'},
      method:'POST',
      dataType:'json',
      success:function(e){
        if(1 == e.data){
          wx.showModal({
            title:'提示',
            content:'提交成功',
            success:function(res){
              if(res.confirm){
                getApp().getUserInfo();
              }else if(res.cancel){
                getApp().getUserInfo();
              }
              setTimeout(function(){
                wx.navigateBack(1)
              },2000)
            }
          })

        }else{
          wx.showModal({
            title:'提示',
            content:'提交失败'
          })
        }
      }
    })
  },

  bindinputdata:function(e){
    var name = e.currentTarget.dataset.name;
    var that = this;
    switch(name){
      case'nickname':
        that.setData({
          'formdata.nickname':e.detail.value
        })
      break;
      case'old':
        that.setData({
          'formdata.old':e.detail.value
        })
      break;
      case'sex':
        that.setData({
          'formdata.sex':e.detail.value
        })
      break;
      case'contract':

        that.setData({
          'formdata.contract':e.detail.value
        })
      break;
      case'address':
        that.setData({
          'formdata.address':e.detail.value
        })
      break;
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      uid:getApp().globalData.userInfo.uid,
      userinfo:getApp().globalData.userInfo,
        formdata:{nickname:getApp().globalData.userInfo.nickname,
            old:getApp().globalData.userInfo.old,
            sex:getApp().globalData.userInfo.sex,
            contract:getApp().globalData.userInfo.contract,
            address:getApp().globalData.userInfo.address}
    })
  },

    //编辑
    bianji:function(e){
      this.setData({
          isbianji:1
      })
    },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})